﻿using MediatR;
using Microsoft.IdentityModel.Tokens;
using System;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.Scalesetting
{
    public class WaitingCircleHtmlhandler : IRequestHandler<WaitingCircleHtmlCommond, PageDTO<SlaughterCircleSelectDTO>>
    {

        private readonly IBateRepository<SlaughterCircle> _SlaughterCirle;
        public WaitingCircleHtmlhandler(IBateRepository<SlaughterCircle> slaughterCirle)    
        {
            _SlaughterCirle = slaughterCirle;
        }
        /// <summary>
        /// 待宰圈列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>                                                                                                            
        public async Task<PageDTO<SlaughterCircleSelectDTO>> Handle(WaitingCircleHtmlCommond request, CancellationToken cancellationToken)
        {

            var list = new PageDTO<SlaughterCircleSelectDTO>() { pageCount = 0, totalCount = 0 };


            var put = (from a in _SlaughterCirle.GetAll()
                      select new SlaughterCircleSelectDTO()
                      {
                          SlaughterCircledId = a.SlaughterCircledId,
                          SlaughterCircledType = a.SlaughterCircledType,
                          SlaughterCircleName = a.SlaughterCircleName,
                          Departmentid = "称重",
                          Head=a.Head, 
                          Stact=a.Stact==0?"启用":"禁用",
                          Remark=a.Remark,
                          CreateMen="李四",
                          CreateTime=DateTime.Now.AddDays(-3),
                          UpdateMen="李四",
                          UpdateTime=DateTime.Now.AddDays(-3),
                      }).ToList();




            if (request.Slaugthertype != null)
            {
                put = put.Where(x => x.SlaughterCircledType.Contains(request.Slaugthertype)).ToList();
            }
            if (request.InChargeofName != null)
            {
                put = put.Where(x => x.SlaughterCircleName.Contains(request.InChargeofName)).ToList();
            }

            list.pageCount = put.Count;
            list.totalCount = (int)Math.Ceiling(put.Count * 1.0 / request.pagesize);

            list.Lists = put.ToList();

            return list;


        }
    }
}
